package principle.prisegregation.improve;

/**
 * 将接口Interface1拆分为独立的几个接口，
 * 类A和类C分别与他们需要的接口建立依赖关系。
 * 也就是采用接口隔离原则
 *
 * @author Fengdong.Duan
 * @create 2023/11/7 10:55
 */
public class Segregation2 {
    public static void main(String[] args) {
        A1 a1 = new A1();
        C1 c1 = new C1();
        a1.use1(new B1());
        a1.use2(new B1());
        c1.use1(new D1());
        c1.use2(new D1());
    }
}

interface Interface2 {
    void operation1();
}

interface Interface3 {

    void operation2();

    void operation3();


}

interface Interface4 {
    void operation4();

    void operation5();
}

class B1 implements Interface2, Interface3 {

    @Override
    public void operation1() {
        System.out.println("类B实现了operation1");
    }

    @Override
    public void operation2() {
        System.out.println("类B实现了operation2");
    }

    @Override
    public void operation3() {
        System.out.println("类B实现了operation3");
    }

}

class D1 implements Interface2, Interface4 {

    @Override
    public void operation1() {
        System.out.println("类D实现了operation1");
    }


    @Override
    public void operation4() {
        System.out.println("类D实现了operation4");
    }

    @Override
    public void operation5() {
        System.out.println("类D实现了operation5");
    }
}

class A1 {
    public void use1(Interface2 interface2) {
        interface2.operation1();
    }

    public void use2(Interface3 interface3) {
        interface3.operation2();
        interface3.operation3();
    }
}

class C1 {
    public void use1(Interface2 interface2) {
        interface2.operation1();
    }

    public void use2(Interface4 interface4) {
        interface4.operation4();
        interface4.operation5();
    }
}
